///////////////////////////////////////////////////////////////////////////////
//
// Copyright
//
///////////////////////////////////////////////////////////////////////////////

package ru.goodcore.logging
{

import flash.errors.IllegalOperationError;
import flash.utils.getClassName;

import ru.goodcore.core.QueryEvent;
import ru.goodcore.core.QueryLink;
import ru.goodcore.utils.ObjectUtil;

/**
 * 
 * @author					Dimarik
 * @version					1.0
 * @playerversion			Flash 9
 * @langversion				3.0
 *
 * @keyword					
 */
public class LoggerLink extends QueryLink
{

	//-------------------------------------------------------------------------
	//
	//  Constructor
	//
	//-------------------------------------------------------------------------

	/**
	 * Constructor
	 */
	public function LoggerLink() {
		super();
	}

	//-------------------------------------------------------------------------
	//
	//  Properties
	//
	//-------------------------------------------------------------------------

	//-------------------------------------------------------------------------
	//
	//  Private variables
	//
	//-------------------------------------------------------------------------

	//---------------------------------
	//  logger
	//---------------------------------
	/**
	 * @private
	 */
	private var _logger:	ILogger;
	/**
	 * @private
	 */	
	private function get logger():ILogger {
		if ( !this._logger ) {
			var child:QueryLink = super.getChildAt(0) as QueryLink;

			if (child) {
				if (child.name) {
					this._logger = Log.getLogger(child.name);
				} else {
					this._logger = Log.getLogger( getClassName(child) );
				}
			}

			if (!this._logger)
				this._logger = Log.getLogger( getClassName(this) );
		}
		return this._logger;
	}

	//-------------------------------------------------------------------------
	//
	//  Interface methods: IQuery
	//
	//-------------------------------------------------------------------------

	public override function perfomQuery(request:Object):void {
		this.logger.info( 'OUT: ' + ObjectUtil.toString(request) );
		super.peer.perfomQuery(request);
	}

	//-------------------------------------------------------------------------
	//
	//  Overridden methods
	//
	//-------------------------------------------------------------------------

	/**
	 * 
	 */
	protected override function handler_queryResult(event:QueryEvent):void {
		this.logger.info( 'IN: ' + ObjectUtil.toString(event.result) );
		super.handler_queryResult(event);
	}

	//-------------------------------------------------------------------------
	//
	//  Protected methods
	//
	//-------------------------------------------------------------------------

	//-------------------------------------------------------------------------
	//
	//  Private methods
	//
	//-------------------------------------------------------------------------

}
}